MsgBox
The message box function is mainly used to prompt the user for a click of a button, or to deliver a message. Please keep in mind you don't use parenthesis [ ( and ) ] unless you are assigning the message box to a variable or you are using it in a statement. Syntax: MsgBox "Microsoft Speech Platform SDK have been installed on your computer.", , "SDK Installation" This syntax will create the following alert: There are 3 main sections to a message box. The first being the main text, the second being the type of box, and the third being the title. In the main text area, you write the message you want the box to display. You put the message in quotes. After the ending quote, you can put a comma , after it, and then put the type. The following are the different types of message boxes (Each type can be replaced with the number and it will do the same thing, the number is shown before the type in the example below): 0 = vbOKOnly - OK button only 1 = vbOKCancel - OK and Cancel buttons 2 = vbAbortRetryIgnore - Abort, Retry, and Ignore buttons 3 = vbYesNoCancel - Yes, No, and Cancel buttons 4 = vbYesNo - Yes and No buttons 5 = vbRetryCancel - Retry and Cancel buttons 16 = vbCritical - Critical Message icon 32 = vbQuestion - Warning Query icon 48 = vbExclamation - Warning Message icon 64 = vbInformation - Information Message icon 0 = vbDefaultButton1 - First button is default 256 = vbDefaultButton2 - Second button is default 512 = vbDefaultButton3 - Third button is default 768 = vbDefaultButton4 - Fourth button is default 0 = vbApplicationModal - Application modal (the current application will not work until the user responds to the message box) 4096 = vbSystemModal - System modal (all applications wont work until the user responds to the message box) In order to get the value returned by the user, you need either a Comparison or a Variable (With a variable, you will need a comparison later to see the value anyway). To check the variable, you would use the type, such as vbYesNo, and put a vb before the input you're checking it for. The following is an example using an If Statement with the vbYesNo 4 parameter. If MsgBox("Do you have five fingers?", vbYesNo, "Question") = vbYes Then MsgBox "Most people do." If you don't put in a type at all, such as in the first example at the top of the page, it would default to vbOkayOnly. Here is the same code using the number 4 instead of the word name vbYesNo. If MsgBox("Do you have five fingers?", 4, "Question") = vbYes Then MsgBox "Most people do." In both cases, it would create a box like this: In order to use the different default button parameters mentioned above, you would add a + after the type, and then which button to default on. If you don't include the button to defualt on, it automatically defaults on the first button. The following example is the same vbYesNo box as above, only with the second button defaulted: If MsgBox("Do you have five fingers?", vbYesNo + vbDefaultButton2, "Question") = vbYes Then MsgBox "Most people do." This would make a box like this: You can use the same principle of the plus + character to add the vbCritical/Question/Exclamation too. Here's an example of a vbYesNo that is with a vbInformation: If MsgBox("Do you have five fingers?", vbYesNo + vbInformation, "Question") = vbYes Then MsgBox "Most people do." This creates the following: Perhaps you wanted that same thing only with the second button defaulted? Here's the code: If MsgBox("Do you have five fingers?", vbYesNo + vbInformation + vbDefaultButton2, "Question") = vbYes Then MsgBox "Most people do." Naturally, it would look like this: Some of the other types mentioned were vbCritical 16, vbQuestion 32, and vbExclamation 48. Here is an example of the vbCritical: MsgBox "", vbCritical That would look like With the 3 different types, the red x would be replaced with a different symbol. vbCritical 16, vbQuestion 32, and vbExclamation 48 in order look like: If you wanted to display a variable in a message box, you would simply use the following code. In this example, the variable name is "TXT", and it contains the text "These are words." TXT = "These are words." MsgBox TXT This makes the following box: If you don't want to include all the parameters (The main text, type, and title), then you simply leave that space empty. Such as if I only wanted the main text, I would do the following: MsgBox "Main text here" Only type: MsgBox "", TypeHere Only title: MsgBox "", , "Title here" Only main text and title: MsgBox "Main text here", , "Title here" Only main text and type: MsgBox "Main text here", TypeHere Only type and title: MsgBox "", TypeHere, "Title here" Related: InputBox (Function) Variables ---- Remember, if you ever need help, you can ask BusyCityGuy on his talk page. ---- Did you find what you needed? Yes! Not completely... Nope. Category:Functions Category:Good Articles Category:Variables